import { defineStore } from 'pinia'
import getCart from '../api/cart'

export const useCartStore = defineStore('cart', {
  state: () => ({
    cartList:[],
    cartTotal:{},
  }),
  actions: {
    async fetchGetCart() {
      try {
        const res = await getCart()

        if (Object.keys(res).length > 0) {
          let { data } = res
          this.cartList = data.cartList
          this.cartTotal = data.cartTotal

        } 
        console.log(res);
        
      } catch (error) {
        console.error('获取购物车数据失败：', error)
      }
    }
  }
})
